package icst.cyber.hrm.bo;

import java.util.List;

import icst.cyber.hrm.dto.JobDTO;
import icst.cyber.hrm.mapper.JobMapperDB;

import org.apache.log4j.Logger;

public class JobBO {
	protected Logger log = Logger.getLogger(JobBO.class);

	public JobBO() {
		super();
	}

	public List<JobDTO> getAllJob() throws Exception {
		log.debug("JobBO.getAllJob.start");

		JobMapperDB mapper = null;
		List<JobDTO> result = null;

		try {
			mapper = new JobMapperDB();
			result = mapper.getAllJob();
		} catch (Exception e) {
			log.error("JobBO.getAllJob", e);
		} finally {
			mapper.closeConnection();
		}

		log.debug("JobBO.getAllJob.end");
		return result;
	}
	
	public JobDTO getOneJob(int id) throws Exception {
		log.debug("JobBO.getAllJob.start");

		JobMapperDB mapper = null;
		JobDTO result = null;

		try {
			mapper = new JobMapperDB();
			result = mapper.getOneJob(id);
		} catch (Exception e) {
			log.error("JobBO.getAllJob", e);
		} finally {
			mapper.closeConnection();
		}

		log.debug("JobBO.getAllJob.end");
		return result;
	}
	
	public void insertJob(String name) throws Exception {
		log.debug("JobBO.insertJob.start");

		JobMapperDB mapper = null;
		
		try {
			mapper = new JobMapperDB();
			mapper.insertJob(name);
		} catch (Exception e) {
			log.error("JobBO.insertJob", e);
		} finally {
			mapper.closeConnection();
		}

		log.debug("JobBO.insertJob.end");
	}
	
	public void updateJob(int id, String name) throws Exception {
		log.debug("JobBO.updateJob.start");

		JobMapperDB mapper = null;
		
		try {
			mapper = new JobMapperDB();
			mapper.updateJob(id, name);
		} catch (Exception e) {
			log.error("JobBO.updateJob", e);
		} finally {
			mapper.closeConnection();
		}

		log.debug("JobBO.updateJob.end");
	}
	
	public void deleteJob(int id) throws Exception {
		log.debug("JobBO.deleteJob.start");

		JobMapperDB mapper = null;
		
		try {
			mapper = new JobMapperDB();
			mapper.deleteJob(id);
		} catch (Exception e) {
			log.error("JobBO.deleteJob", e);
		} finally {
			mapper.closeConnection();
		}

		log.debug("JobBO.deleteJob.end");
	}
}
